package cn.hesion.leetcode;
/**
 * ClassName: TimeRequiredToBuy <br/>
 * Description: <br/>
 * date: 2022/5/17 6:04<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

/**
 *
 * @author: hesion
 * @create: 2022-05-17 06:04
 **/
public class TimeRequiredToBuy {
    public int timeRequiredToBuy(int[] tickets, int k) {
        int sumWaitTime=0;
        int n = tickets.length;
        while (tickets[k] != 0){
            for (int i = 0; i < n; i++) {
                if(tickets[i]!=0){
                    tickets[i]--;
                    ++sumWaitTime;
                }
                if(tickets[k]==0){
                    break;
                }
            }
       }
        return sumWaitTime;
    }
}
